import * as fs from "node:fs";

class ApplicationContext {
    config = "./config/application.json";
    dirConfig = '"./application.json"'
    srcConfig = './src/application.json'

    public async loadConfig() {
        return new Promise<any>((resolve, reject) => {
            try {
                const confPath = fs.existsSync(this.config) ? this.config :
                    fs.existsSync(this.dirConfig) ? this.dirConfig : this.srcConfig;
                fs.readFile(confPath, 'utf8', (err, data) => {
                    resolve(JSON.parse(data))
                })
            } catch (e) {
                reject(e)
            }
        });
    }
}

export const env = new ApplicationContext();